package com.tiantianyuegou.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.tiantianyuegou.util.LoadingDialog;
import com.tiantianyuegou.util.SelfUtils;
import com.tiantianyuegou.util.Tools;
import com.trouble.framework.utils.MD5;
import com.tiantianyuegou.R;
import com.tiantianyuegou.adapter.GridImgAdapter;
import com.tiantianyuegou.adapter.MyGoodsInfoAdapter;
import com.tiantianyuegou.adapter.ProcessAdapter;
import com.tiantianyuegou.constant.Constant;
import com.tiantianyuegou.enums.PayType;
import com.tiantianyuegou.http.ApiDefine;
import com.tiantianyuegou.http.SPHelper;
import com.tiantianyuegou.model.PayOrderInfo;
import com.tiantianyuegou.pay.AccountPay;
import com.tiantianyuegou.pay.OnMyPayListner;
import com.tiantianyuegou.view.MyDialogTextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单详情
 */
public class MyOrderDetailsActivity extends BaseActivity implements View.OnClickListener, OnMyPayListner {

    private ImageView img_title;
    private TextView text_title, text_menu;

    private TextView text_details_prompt, text_name, text_phone, text_address, text_shop_name, text_goodsnumber, text_goodsxiadan,

    text_details_freight_num, text_details_real_num, text_pay_time, text_send_time, text_receive_time;
    private ImageView img_shop, img_details_goods_picture;
    private ListView list_process, list_goods_info;

    private RelativeLayout relative_seller, relative_order;

    private TextView text_take_reason, text_take_money, text_take_explain;

    private MyGoodsInfoAdapter goodsInfoAdapter;
    private ProcessAdapter processAdapter;

    private Button btn_shouhuo, btn_quxiaodingdan, btn_fukuan, btn_tuikuan, btn_delete, btn_eva, btn_fahuo,
            btn_jujue, btn_queren, btn_eva_r, btn_delete2;
    private LinearLayout view_details;

    private String[] num = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
    private String[] strStatus = {"订单生成", "已支付", "已发货", "已收货", "已评价", "申请退款中", "已退款", "交易取消", "交易关闭"};

    private JSONArray product;

    private JSONObject shopList;
    private String toId;
    private String TAG = "MyOrderDetailsActivity";
    private String toNumber, toPayTime, toAddtime, toTodTime, toReceiveTime;

    private LoadingDialog loadingDialog;

    private String toStatus, toPayPrice;
    private String strName, strNum;

    private GridView mGird_img;
    private List<GridImgAdapter.ReasonImg> mPicData;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order_details);
        init();
        Tools.changeSystemBar(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        loadGoodsInfo();
    }

    @Override
    public void findViewByIds() {

    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }


    private void init() {
        text_title = (TextView) findViewById(R.id.text_title);
        img_title = (ImageView) findViewById(R.id.img_title);
        text_title.setText(R.string.details_title);
        img_title.setOnClickListener(this);

        text_details_prompt = (TextView) findViewById(R.id.text_details_prompt);
        text_name = (TextView) findViewById(R.id.text_name);
        text_phone = (TextView) findViewById(R.id.text_phone);
        text_address = (TextView) findViewById(R.id.text_address);
        text_shop_name = (TextView) findViewById(R.id.text_shop_name);

        text_take_reason = (TextView) findViewById(R.id.text_take_reason);
        text_take_money = (TextView) findViewById(R.id.text_take_money);
        text_take_explain = (TextView) findViewById(R.id.text_take_explain);

        text_goodsnumber = (TextView) findViewById(R.id.text_goodsnumber);
        text_goodsxiadan = (TextView) findViewById(R.id.text_goodsxiadan);
        text_pay_time = (TextView) findViewById(R.id.text_goodspay);
        text_send_time = (TextView) findViewById(R.id.text_goodssend);
        text_receive_time = (TextView) findViewById(R.id.text_goodsmake);
        //text_details_goods_name = (TextView) findViewById(R.id.text_details_goods_name);
        //text_details_goods_price = (TextView) findViewById(R.id.text_details_goods_price);
        //text_details_goods_num = (TextView) findViewById(R.id.text_details_goods_num);
        //text_details_goods_info = (TextView) findViewById(R.id.text_details_goods_info);


        text_details_freight_num = (TextView) findViewById(R.id.text_details_freight_num);
        text_details_real_num = (TextView) findViewById(R.id.text_details_real_num);

        btn_shouhuo = (Button) findViewById(R.id.btn_shouhuo);
        btn_fukuan = (Button) findViewById(R.id.btn_fukuan);
        btn_quxiaodingdan = (Button) findViewById(R.id.btn_quxiaodingdan);
        btn_tuikuan = (Button) findViewById(R.id.btn_tuikuan);
        view_details = (LinearLayout) findViewById(R.id.view_details);

        btn_delete = (Button) findViewById(R.id.btn_delete);
        btn_eva = (Button) findViewById(R.id.btn_eva);
        btn_fahuo = (Button) findViewById(R.id.btn_fahuo);
        btn_jujue = (Button) findViewById(R.id.btn_jujue);
        btn_queren = (Button) findViewById(R.id.btn_queren);
        btn_eva_r = (Button) findViewById(R.id.btn_eva_r);
        btn_delete2 = (Button) findViewById(R.id.btn_delete2);

        relative_seller = (RelativeLayout) findViewById(R.id.relative_seller);
        relative_order = (RelativeLayout) findViewById(R.id.relative_order);

//        view_details.setVisibility(View.VISIBLE);
//        btn_quxiaodingdan.setVisibility(View.VISIBLE);
//        btn_fukuan.setVisibility(View.VISIBLE);
        btn_shouhuo.setOnClickListener(this);
        btn_quxiaodingdan.setOnClickListener(this);
        btn_fukuan.setOnClickListener(this);
        btn_tuikuan.setOnClickListener(this);
        btn_delete.setOnClickListener(this);
        btn_eva.setOnClickListener(this);
        btn_fahuo.setOnClickListener(this);
        btn_jujue.setOnClickListener(this);
        btn_queren.setOnClickListener(this);
        btn_eva_r.setOnClickListener(this);
        btn_delete2.setOnClickListener(this);

        try {
            shopList = new JSONObject(getIntent().getStringExtra("shopList"));
            toId = shopList.getString("toId");
            SPHelper.setToId(toId);
            SPHelper.setTSId(shopList.getString("tsId"));
            Log.e(TAG, "toId     " + toId);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        img_shop = (ImageView) findViewById(R.id.img_shop);
        //img_details_goods_picture = (ImageView) findViewById(R.id.img_details_goods_picture);

        if ("member".equals(SPHelper.getTYPE())) {
            img_shop.setImageResource(R.mipmap.shangcheng);
        } else if ("seller".equals(SPHelper.getTYPE())) {
            img_shop.setImageResource(R.mipmap.d_6);
        }

        list_process = (ListView) findViewById(R.id.list_process);
        list_goods_info = (ListView) findViewById(R.id.list_goods_info);

        list_process.setFocusable(false);
        list_goods_info.setFocusable(false);

        processAdapter = new ProcessAdapter(this);


        mGird_img = (GridView) findViewById(R.id.grid_img);
        text_take_reason = (TextView) findViewById(R.id.text_take_reason);
        text_take_money = (TextView) findViewById(R.id.text_take_money);
        text_take_explain = (TextView) findViewById(R.id.text_take_explain);
    }


    //获得商品的详细信息
    private void loadGoodsInfo() {
        loadingDialog = new LoadingDialog(this);
        loadingDialog.setMsg("请稍等");
        loadingDialog.showDialog();
        RequestParams params = new RequestParams();
        params.addBodyParameter("toId", toId);
        loadData(HttpRequest.HttpMethod.POST, ApiDefine.ORDER_DETAIL, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                String response = responseInfo.result;
                Log.e(TAG, "MyOrderDetailsActivity     " + response);

                try {
                    JSONObject object = new JSONObject(response);
                    showMsg(object.getString("message"));
                    if ("100".equals(object.getString("code"))) {

                        JSONObject address = object.getJSONObject("address");
                        text_name.setText(address.getString("tmaName"));

                        text_phone.setText(address.getString("tmaPhone"));
                        text_address.setText(address.getString("provice") + "  " + address.getString("city") + "  " + address.getString("county") + "  " + address.getString("tmaAddress"));

                        JSONObject detail = object.getJSONObject("detail");
                        if ("member".equals(SPHelper.getTYPE())) {
                            text_shop_name.setText(detail.getString("tsName"));
                        }else if("seller".equals(SPHelper.getTYPE())){
                            text_shop_name.setText(detail.getString("tmName"));
                        }

                        Double freight = Double.valueOf(detail.getString("toFreight"));
                        text_details_freight_num.setText("￥" + new DecimalFormat("0.00").format(freight));
                        text_details_real_num.setText("￥" + new DecimalFormat("0.00").format(Double.valueOf((detail.getString("toPayPrice")))));
                        toStatus = detail.getString("toStatus");
                        toPayPrice = detail.getString("toPayPrice");
                        text_goodsnumber.setText("订单编号:" + detail.getString("toNumber"));
                        if (!"null".equals(detail.getString("toAddtime"))) {
                            text_goodsxiadan.setText("下单时间:" + new SelfUtils().getDate(detail.getString("toAddtime")));
                        } else {
                            text_goodsxiadan.setVisibility(View.GONE);
                        }

                        if (!"null".equals(detail.getString("toPayTime"))) {
                            text_pay_time.setText("付款时间:" + new SelfUtils().getDate(detail.getString("toPayTime")));
                        } else {
                            text_pay_time.setVisibility(View.GONE);
                        }

                        if (!"null".equals(detail.getString("toTodTime"))) {
                            text_send_time.setText("发货时间:" + new SelfUtils().getDate(detail.getString("toTodTime")));
                        } else {
                            text_send_time.setVisibility(View.GONE);
                        }

                        if (!"null".equals(detail.getString("toReceiveTime"))) {
                            text_receive_time.setText("成交时间:" + new SelfUtils().getDate(detail.getString("toReceiveTime")));
                        } else {
                            text_receive_time.setVisibility(View.GONE);
                        }

                        for (int i = 0; i < num.length; i++) {
                            if (toStatus.equals(num[i])) {
                                text_details_prompt.setText(strStatus[i]);
                            }
                        }

                        JSONArray products = object.getJSONArray("products");

                        goodsInfoAdapter = new MyGoodsInfoAdapter(MyOrderDetailsActivity.this);
                        goodsInfoAdapter.Data(products);
                        list_goods_info.setAdapter(goodsInfoAdapter);

                        toNumber = detail.getString("toNumber");
                        toPayTime = detail.getString("toPayTime");
                        toAddtime = detail.getString("toAddtime");
                        toTodTime = detail.getString("toTodTime");
                        toReceiveTime = detail.getString("toReceiveTime");

                        if ("member".equals(SPHelper.getTYPE())) {
                            if ("3".equals(detail.getString("toStatus"))) {
                                btn_tuikuan.setVisibility(View.VISIBLE);
                            } else {
                                btn_tuikuan.setVisibility(View.GONE);
                            }

                            if ("1".equals(detail.getString("toStatus"))) {
                                view_details.setVisibility(View.VISIBLE);
                                btn_quxiaodingdan.setVisibility(View.VISIBLE);
                                btn_fukuan.setVisibility(View.VISIBLE);

                            } else {
                                btn_quxiaodingdan.setVisibility(View.GONE);
                                btn_fukuan.setVisibility(View.GONE);
                                view_details.setVisibility(View.GONE);
                            }

                            if ("3".equals(detail.getString("toStatus"))) {
                                btn_shouhuo.setVisibility(View.VISIBLE);
                            } else {
                                btn_shouhuo.setVisibility(View.GONE);
                            }

                            if ("4".equals(detail.getString("toStatus"))) {
                                btn_delete2.setVisibility(View.VISIBLE);
                                btn_eva_r.setVisibility(View.VISIBLE);
                                view_details.setVisibility(View.VISIBLE);
                            } else {
                                btn_delete2.setVisibility(View.GONE);
                                btn_eva_r.setVisibility(View.GONE);
                                view_details.setVisibility(View.GONE);
                            }
                        } else if ("seller".equals(SPHelper.getTYPE())) {
                            btn_tuikuan.setVisibility(View.GONE);

                            btn_quxiaodingdan.setVisibility(View.GONE);
                            btn_fukuan.setVisibility(View.GONE);

                            if ("2".equals(detail.getString("toStatus"))) {
                                view_details.setVisibility(View.GONE);
                                btn_fahuo.setVisibility(View.VISIBLE);
                            } else {
                                btn_fahuo.setVisibility(View.GONE);
                            }

                            if ("6".equals(detail.getString("toStatus"))) {
                                relative_seller.setVisibility(View.VISIBLE);
                                view_details.setVisibility(View.VISIBLE);
                                btn_jujue.setVisibility(View.VISIBLE);
                                btn_queren.setVisibility(View.VISIBLE);
                                text_pay_time.setVisibility(View.GONE);
                                text_send_time.setVisibility(View.GONE);
                                text_receive_time.setVisibility(View.GONE);
                                text_goodsnumber.setVisibility(View.GONE);
                                text_goodsxiadan.setVisibility(View.GONE);
                                getReason();
                            }

                        }

                        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
                        String[] strList = {toNumber, toPayTime, toAddtime, toTodTime, toReceiveTime};
                        Map<String, String> map = new HashMap<String, String>();
//                        for (int i = 0; i < 5; i++) {
//
//                            if (!"".equals(strList[i]) && strList[i] != null && strList[i].length() != 0) {
//                                map.put("same", strList[i]);
//                                Log.e(TAG, "for  " + i + "  " + 1 + !"".equals(strList[i]) + "   2" + (strList[i] != null) + "   3" + (strList[i].length() != 0));
//                                Log.e(TAG, "for  " + i + "  " + map.get("same"));
//                                list.add(map);
//                            }
//
//                        }

                        processAdapter.Data(list);
                        list_process.setAdapter(processAdapter);
                        processAdapter.notifyDataSetChanged();

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                loadingDialog.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                loadingDialog.dismiss();
            }
        });

    }

    //获取退款信息
    private void getReason() {
        final LoadingDialog loadingDialog = new LoadingDialog(this);
        loadingDialog.setMsg("正在获取详情");
        loadingDialog.show();
        RequestParams params = new RequestParams();
        params.addBodyParameter("toId", toId);
        loadData(HttpRequest.HttpMethod.POST, ApiDefine.GET_REASON_DETAIL, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                Log.e("TAG", "get reason detail response:" + responseInfo.result);
                loadingDialog.dismiss();
                if (TextUtils.isEmpty(responseInfo.result)) {
                    showMsg("暂无退款说明");
                } else {
                    try {
                        JSONObject root = new JSONObject(responseInfo.result);
                        String code = root.getString("code");
                        if ("100".equals(code)) {
                            mPicData = new ArrayList<>();
                            JSONObject value = root.getJSONObject("list");
                            text_take_reason.setText(value.getString("twName"));
                            Double price = Double.valueOf(value.getString("trMoney"));
                            text_take_money.setText("￥" + new DecimalFormat("0.00").format(price));
                            text_take_explain.setText(value.getString("trDesp"));

                            String pics = value.getString("trPic");
                            if (pics.contains(",")) {
                                String[] picUrl = pics.split(",");
                                for (int i = 0; i < picUrl.length; i++) {
                                    GridImgAdapter.ReasonImg img = new GridImgAdapter.ReasonImg();
                                    img.setImgUrl(picUrl[i]);
                                    mPicData.add(img);
                                }
                            } else {
                                GridImgAdapter.ReasonImg img = new GridImgAdapter.ReasonImg();
                                img.setImgUrl(pics);
                                mPicData.add(img);
                            }

                            mGird_img.setAdapter(new GridImgAdapter(MyOrderDetailsActivity.this, mPicData));
                        } else {
                            showMsg(root.getString("message"));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                loadingDialog.dismiss();
            }
        });
//        mGird_img.setAdapter(new SimpleAdapter());
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_title:
                finish();
                break;

            case R.id.btn_shouhuo:
                PayOrderInfo orderInfo1 = new PayOrderInfo();
                orderInfo1.setOrderNo(toNumber);
                orderInfo1.setGoodsName("测试001");
                orderInfo1.setGoodsDesc("这是测试");
                orderInfo1.setGoodsPrice(toPayPrice);
                orderInfo1.setType("receive");
                if (true) {
                    SPHelper.setToId(toId);
                    AccountPay pay = new AccountPay(1);
                    pay.pay(this, orderInfo1, this);
                } else {
                    MyDialogTextView dialog = new MyDialogTextView(this, "提示", "您还未设置支付密码，为保护账户安全，请先设置支付密码!");
                    dialog.setDialogCallback(new MyDialogTextView.DialogCallback() {
                        @Override
                        public void dialogOpt() {
                            Intent intent = new Intent(MyOrderDetailsActivity.this, SettingBalanceActivity.class);
                            startActivityForResult(intent, Constant.SETTING_BALANCE_REQUEST);
                        }
                    });
                    dialog.show();
                }
                break;

            case R.id.btn_quxiaodingdan:

                loadQuXiao();
                break;

            case R.id.btn_fukuan:
                Intent pay = new Intent(MyOrderDetailsActivity.this, PayActivity.class);
                pay.putExtra("orderNo", toNumber);
                pay.putExtra("orderId", SPHelper.getToId());
                startActivity(pay);
                break;

            case R.id.btn_tuikuan:
                Intent btn_tuikuan = new Intent();
                btn_tuikuan.putExtra("toId", toId);
                btn_tuikuan.putExtra("money", toPayPrice);
                btn_tuikuan.putExtra("type", "1");
                btn_tuikuan.putExtra("toStatus", toStatus);
                btn_tuikuan.setClass(MyOrderDetailsActivity.this, RefundActivity.class);
                startActivity(btn_tuikuan);
                break;

            case R.id.btn_delete:
                deletePopupwindow();
                // finish();
                break;

            case R.id.btn_eva:
                Intent intent = new Intent(MyOrderDetailsActivity.this, MyEvaluateActivity.class);
                intent.putExtra("products", shopList.toString());
                startActivity(intent);
                break;

            case R.id.btn_eva_r:
                Intent intent2 = new Intent(MyOrderDetailsActivity.this, MyEvaluateActivity.class);
                intent2.putExtra("products", shopList.toString());
                startActivity(intent2);
                break;

            case R.id.btn_delete2:
                deletePopupwindow();

                break;

            case R.id.btn_fahuo:

                orderPopupwindow();
                break;

            case R.id.btn_jujue:

                loadTuikuan("2");
                break;
            case R.id.btn_queren:
                loadTuikuan("1");
                break;

            default:
                break;
        }
    }

    private void loadQuXiao() {
        loadingDialog = new LoadingDialog(this);
        loadingDialog.setMsg("请稍等");
        loadingDialog.showDialog();
        RequestParams params = new RequestParams();
        params.addBodyParameter("tmId", SPHelper.getTmId());
        params.addBodyParameter("toId", SPHelper.getToId());
        loadData(HttpRequest.HttpMethod.POST, ApiDefine.ORDER_CANCEL, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                String response = responseInfo.result;
                Log.e(TAG, "MyOrderDetailsActivity     " + response);

                try {
                    JSONObject object = new JSONObject(response);
                    showMsg(object.getString("message"));
                    if ("100".equals(object.getString("code"))) {

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                loadingDialog.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                loadingDialog.dismiss();
            }
        });
    }

    private void loadDelete() {
        loadingDialog = new LoadingDialog(this);
        loadingDialog.setMsg("请稍等");
        loadingDialog.showDialog();
        RequestParams params = new RequestParams();
        params.addBodyParameter("tmId", SPHelper.getTmId());
        params.addBodyParameter("toId", SPHelper.getToId());
        Log.e("toid", ",toId     " + SPHelper.getToId());

        loadData(HttpRequest.HttpMethod.POST, ApiDefine.ORDER_DELTE, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                String response = responseInfo.result;
                Log.e(TAG, TAG + "     " + response);
                Log.e(TAG, TAG + "toId     " + SPHelper.getToId());
                try {
                    JSONObject object = new JSONObject(response);
                    showMsg(object.getString("message"));
                    if ("100".equals(object.getString("code"))) {

                        loadingDialog.dismiss();
                        finish();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                loadingDialog.dismiss();
            }

            @Override
            public void onFailure(HttpException e, String s) {
                loadingDialog.dismiss();
            }
        });


    }

    private PopupWindow popupWindow = null;
    EditText edit_name, edit_num;

    @SuppressLint("InflateParams")
    public void orderPopupwindow() {
        View view = getLayoutInflater().inflate(R.layout.popupwindow_edittext,
                null);

        edit_name = (EditText) view.findViewById(R.id.edit_name);
        edit_num = (EditText) view.findViewById(R.id.edit_num);

        TextView txt_cancel = (TextView) view.findViewById(R.id.txt_cancel);
        txt_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                popupWindow.dismiss();

            }
        });
        TextView txt_confirm = (TextView) view.findViewById(R.id.txt_confirm);
        txt_confirm.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                strName = edit_name.getText().toString();
                strNum = edit_num.getText().toString();
                loadSend();
                popupWindow.dismiss();

            }
        });

        popupWindow = new PopupWindow(view, ViewPager.LayoutParams.MATCH_PARENT,
                ViewPager.LayoutParams.MATCH_PARENT, true);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.showAtLocation(list_process, Gravity.CENTER, 0, 0);

    }

    public void deletePopupwindow() {
        View view = getLayoutInflater().inflate(R.layout.my_dialog_text,
                null);

        TextView text_dialog_title, text_dialog_content;
        Button btn_cancel, btn_confirm;

        text_dialog_title = (TextView) view.findViewById(R.id.text_dialog_title);
        text_dialog_content = (TextView) view.findViewById(R.id.text_dialog_content);
        btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        btn_confirm = (Button) view.findViewById(R.id.btn_confirm);

        text_dialog_title.setText("删除订单");
        text_dialog_content.setText("您确定删除订单吗？");
        text_dialog_title.setTextSize(17f);
        text_dialog_content.setTextSize(14f);
        btn_cancel.setTextColor(getResources().getColor(R.color.dialog_btn_color));
        btn_confirm.setTextColor(getResources().getColor(R.color.dialog_btn_color));
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });

        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                loadDelete();

                popupWindow.dismiss();
            }
        });


        popupWindow = new PopupWindow(view, ViewPager.LayoutParams.WRAP_CONTENT,
                400, true);

        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.showAtLocation(list_process, Gravity.CENTER, 0, 0);

    }

    public void quXiaoPopupwindow() {
        View view = getLayoutInflater().inflate(R.layout.my_dialog_text,
                null);

        TextView text_dialog_title, text_dialog_content;
        Button btn_cancel, btn_confirm;

        text_dialog_title = (TextView) view.findViewById(R.id.text_dialog_title);
        text_dialog_content = (TextView) view.findViewById(R.id.text_dialog_content);

        btn_cancel = (Button) view.findViewById(R.id.btn_cancel);
        btn_confirm = (Button) view.findViewById(R.id.btn_confirm);

        text_dialog_title.setText("取消订单");
        text_dialog_content.setText("您确定取消订单吗？");

        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });

        btn_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                loadQuXiao();

                popupWindow.dismiss();
            }
        });

        popupWindow = new PopupWindow(view, ViewPager.LayoutParams.WRAP_CONTENT,
                400, true);


        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.showAtLocation(list_process, Gravity.CENTER, 0, 0);

    }


    private void loadSend() {
        RequestParams params = new RequestParams();
        params.addBodyParameter("tmId", SPHelper.getTmId());
        params.addBodyParameter("toId", SPHelper.getToId());
        params.addBodyParameter("company", strName);
        params.addBodyParameter("number", strNum);
        loadData(HttpRequest.HttpMethod.POST, ApiDefine.STORE_SEND, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                String response = responseInfo.result;
                Log.e(TAG, TAG + "     " + response);
                try {
                    JSONObject object = new JSONObject(response);
                    showMsg(object.getString("message"));
                    if ("100".equals(object.getString("code"))) {
                        //refreshListView.removeViewAt(id);


                        //   popupWindow.dismiss();
                        finish();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
    }

    //我是商家中的退货退款的操作
    private void loadTuikuan(String type) {
        final LoadingDialog loadingDialog = new LoadingDialog(this);
        loadingDialog.setMsg("正在提交数据...");
        loadingDialog.show();
        RequestParams params = new RequestParams();
        params.addBodyParameter("toId", toId);
        params.addBodyParameter("md5", MD5.md5(MD5.md5(SPHelper.getPassword()).toLowerCase() + toId).toLowerCase());
        params.addBodyParameter("type", type);
        Log.e("TAG", "password:" + SPHelper.getPassword());
        Log.e("TAG", "password:" + MD5.md5(SPHelper.getPassword()));
        Log.e("TAG", "password :" + MD5.md5(SPHelper.getPassword()).toLowerCase());
        Log.e("TAG", "tuikuan request:" + toId + ":"
                + MD5.md5(MD5.md5(SPHelper.getPassword()).toLowerCase() + toId).toLowerCase() + ":" + type);
        loadData(HttpRequest.HttpMethod.POST, ApiDefine.STORE_REFUND, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                loadingDialog.dismiss();
                String response = responseInfo.result;
                Log.e(TAG, TAG + "   " + response);
                try {
                    JSONObject object = new JSONObject(response);
                    if ("100".equals(object.getString("code"))) {
                        finish();
                    } else {
                        showMsg(object.getString("message"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                loadingDialog.dismiss();
            }
        });

    }

    @Override
    public void onPayStart(PayType payType) {

    }

    @Override
    public void onPaySuccessed(PayType payType, String s) {
        finish();
    }

    @Override
    public void onPayFailed(PayType payType, String s) {

    }

    @Override
    public void onPayCanceled(PayType payType) {

    }

    @Override
    public void onPayConfirming(PayType payType) {

    }
}